/**************************************************************************//**
  \file  sensors.h

  \brief The header file describes the sensors interface.

  \author
    Atmel Corporation: http://www.atmel.com \n
    Support email: avr@atmel.com

  Copyright (c) 2008-2012, Atmel Corporation. All rights reserved.
  Licensed under Atmel's Limited License Agreement (BitCloudTM).

  \internal
  History:
    29/05/07 E. Ivanov - Created
*******************************************************************************/

#ifndef _SENSORS_H
#define _SENSORS_H

/******************************************************************************
                   Includes section
******************************************************************************/
// \cond
#include <types.h>
// \endcond

/******************************************************************************
                   Define(s) section
******************************************************************************/
// \cond
//#define SENSOR_TEMPERATURE	1
//#define SENSOR_PRESSURE		2
//#define SENSOR_HUMIDITY		3
//#define SENSOR_UV			4
//#define SENSOR_PV			5
//#define SENSOR_BATTERY		6
// \endcond

typedef void (*BspTemperatureCb_t)(bool result, int16_t data);
typedef void (*BspPressureCb_t)(bool result, uint32_t data);
typedef void (*BspHumidityCb_t)(bool result, uint16_t data);
typedef void (*BspUVCb_t)(bool result, uint16_t data);
typedef void (*BspPVCb_t)(bool result, uint16_t data);
typedef void (*BspWindDirCb_t)(bool result, uint16_t data);
typedef void (*BspWindSpeedCb_t)(uint16_t data);
typedef void (*BspBatteryCb_t)(uint16_t data);
typedef void (*BspAdcCb_t)(uint16_t data);

/******************************************************************************
                   Prototypes section
******************************************************************************/
/***************************************************************************//**
\brief Opens temperature sensor.
\return
  BC_FAIL - sensor has been already open. \n
  BC_SUCCESS - otherwise.
*******************************************************************************/
result_t BSP_OpenTemperatureSensor(void);

/***************************************************************************//**
\brief Closes the temperature sensor.
\return
  BC_FAIL - if a hardware error has occurred or
            there is uncompleted ReadData request. \n
  BC_SUCCESS - otherwise.
*******************************************************************************/
result_t BSP_CloseTemperatureSensor(void);

/**************************************************************************//**
\brief Reads data from the temperature sensor.
\param[in]
    f - callback.
    result - the result of the requested operation.
             true - operation finished successfully, false - some error has
             occurred.
    data - sensor data.
\return
  BC_FAIL - previous request was not completed. \n
  BC_SUCCESS - otherwise.
******************************************************************************/
result_t BSP_ReadTemperatureData(BspTemperatureCb_t f);

/***************************************************************************//**
\brief Opens pressure sensor.
\return
  BC_FAIL - sensor has been already open. \n
  BC_SUCCESS - otherwise.
*******************************************************************************/
result_t BSP_OpenPressureSensor(void);

/***************************************************************************//**
\brief Closes the pressure sensor.
\return
  BC_FAIL - if a hardware error has occurred or
            there is uncompleted ReadData request. \n
  BC_SUCCESS - otherwise.
*******************************************************************************/
result_t BSP_ClosePressureSensor(void);

/**************************************************************************//**
\brief Reads data from the pressure sensor.
\param[in]
    f - callback.
    result - the result of the requested operation.
             true - operation finished successfully, false - some error has
             occurred.
    data - sensor data.
\return
  BC_FAIL - previous request was not completed. \n
  BC_SUCCESS - otherwise.
******************************************************************************/
result_t BSP_ReadPressureData(BspPressureCb_t f);

/**************************************************************************//**
\brief Reads temperature from the pressure sensor.
\param[in]
    f - callback.
    result - the result of the requested operation.
             true - operation finished successfully, false - some error has
             occurred.
    data - sensor data.
\return
  BC_FAIL - previous request was not completed. \n
  BC_SUCCESS - otherwise.
******************************************************************************/
result_t BSP_ReadPressureTemp(BspTemperatureCb_t f);

/***************************************************************************//**
\brief Opens humidity sensor.

\return
  BC_FAIL - sensor has been already open. \n
  BC_SUCCESS - otherwise.
*******************************************************************************/
result_t BSP_OpenHumiditySensor(void);

/***************************************************************************//**
\brief Closes the humidity sensor.

\return
  BC_FAIL - if a hardware error has occurred or
            there is uncompleted ReadData request. \n
  BC_SUCCESS - otherwise.
*******************************************************************************/
result_t BSP_CloseHumiditySensor(void);

/**************************************************************************//**
\brief Reads data from the humidity sensor.
\param[in]
    result - the result of the requested operation.
             true - operation finished successfully, false - some error has
             occurred.
\param[in]
    data - sensor data.
\return
    BC_FAIL - previous request was not completed. \n
    BC_SUCCESS - otherwise.
******************************************************************************/
result_t BSP_ReadHumidityData(BspHumidityCb_t f);

/***************************************************************************//**
\brief Opens the UV sensor.
\return
  BC_FAIL - sensor has been already open. \n
  BC_SUCCESS - otherwise.
*******************************************************************************/
result_t BSP_OpenUVSensor(void);

/***************************************************************************//**
\brief Closes the UV sensor.
\return
  BC_FAIL - if a hardware error has occurred or
         there is uncompleted ReadData request. \n
  BC_SUCCESS  - otherwise.
*******************************************************************************/
result_t BSP_CloseUVSensor(void);

/**************************************************************************//**
\brief Reads data from the light sensor.
\param[in]
    f - callback.
    result - the result of the requested operation.
             true - operation finished successfully, false - some error has
             occurred.
    data - sensor data.
\return
  BC_FAIL - previous request was not completed. \n
  BC_SUCCESS - otherwise.
******************************************************************************/
result_t BSP_ReadUVData(BspUVCb_t f);

/***************************************************************************//**
\brief Opens the PV sensor.
\return
  BC_FAIL - sensor has been already open. \n
  BC_SUCCESS - otherwise.
*******************************************************************************/
result_t BSP_OpenPVSensor(void);

/***************************************************************************//**
\brief Closes the PV sensor.
\return
  BC_FAIL - if a hardware error has occurred or
         there is uncompleted ReadData request. \n
  BC_SUCCESS  - otherwise.
*******************************************************************************/
result_t BSP_ClosePVSensor(void);

/**************************************************************************//**
\brief Reads data from the PV sensor.
\param[in]
    result - the result of the requested operation.
             true - operation finished successfully, false - some error has
             occurred.
\param[in]
    data - sensor data.
\return
    BC_FAIL - previous request was not completed. \n
    BC_SUCCESS - otherwise.
******************************************************************************/
result_t BSP_ReadPVData(BspPVCb_t f);

/***************************************************************************//**
\brief Opens the Wind Direction sensor.
\return
  BC_FAIL - sensor has been already open. \n
  BC_SUCCESS - otherwise.
*******************************************************************************/
result_t BSP_OpenWindDirectionSensor(void);

/***************************************************************************//**
\brief Closes the Wind Direction sensor.
\return
  BC_FAIL - if a hardware error has occurred or
         there is uncompleted ReadData request. \n
  BC_SUCCESS  - otherwise.
*******************************************************************************/
result_t BSP_CloseWindDirectionSensor(void);

/**************************************************************************//**
\brief Reads data from the Wind Direction sensor.
\param[in]
    result - the result of the requested operation.
             true - operation finished successfully, false - some error has
             occurred.
\param[in]
    data - sensor data.
\return
    BC_FAIL - previous request was not completed. \n
    BC_SUCCESS - otherwise.
******************************************************************************/
result_t BSP_ReadWindDirectionData(BspWindDirCb_t f);

/***************************************************************************//**
\brief Opens the Wind Speed sensor.
\return
  BC_FAIL - sensor has been already open. \n
  BC_SUCCESS - otherwise.
*******************************************************************************/
result_t BSP_OpenWindSpeedSensor(void);

/***************************************************************************//**
\brief Closes the Wind Speed sensor.
\return
  BC_FAIL - if a hardware error has occurred or
         there is uncompleted ReadData request. \n
  BC_SUCCESS  - otherwise.
*******************************************************************************/
result_t BSP_CloseWindSpeedSensor(void);

/**************************************************************************//**
\brief Reads data from the Wind Speed sensor.
\param[in]
    result - the result of the requested operation.
             true - operation finished successfully, false - some error has
             occurred.
\param[in]
    data - sensor data.
\return
    BC_FAIL - previous request was not completed. \n
    BC_SUCCESS - otherwise.
******************************************************************************/
result_t BSP_ReadWindSpeedData(BspWindSpeedCb_t f);

/***************************************************************************//**
\brief Opens the battery sensor.
\return
  BC_FAIL - sensor has been already open. \n
  BC_SUCCESS - otherwise.
*******************************************************************************/
result_t BSP_OpenBatterySensor(void);

/***************************************************************************//**
\brief Closes the battery sensor.
\return
  BC_FAIL - sensor was not opened. \n
  BC_SUCCESS  - otherwise.
*******************************************************************************/
result_t BSP_CloseBatterySensor(void);

/**************************************************************************//**
\brief Reads data from battery sensor.
\param[in]
    callback - callback function.
    data - sensor data.
    Can use (4ul * data * 125ul * 3ul) / (1024ul * 100ul) formula to count \n
    battery data in Volts (for avr).
\return
  BC_FAIL - previous request was not completed, or sensor was not opened. \n
  BC_SUCCESS - otherwise.
******************************************************************************/
result_t BSP_ReadBatteryData(BspBatteryCb_t cb);

/***************************************************************************//**
\brief Opens the Analog to Digital Converter.

\return
  BC_FAIL - sensor has been already open. \n
  BC_SUCCESS - otherwise.
*******************************************************************************/
result_t BSP_OpenAdc(void);

/***************************************************************************//**
\brief Closes the Analog to Digital Converter.

\return
  BC_FAIL - if a hardware error has occurred or
            there is uncompleted ReadData request. \n
  BC_SUCCESS - otherwise.
*******************************************************************************/
result_t BSP_CloseAdc(void);

#endif/* _SENSORS_H */
// eof sensors.h

